﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JoeyLibs.Utility.Log
{
    public class LogUtility
    {
        /// <summary>
        /// 日志信息标题
        /// </summary>
        public const string MESSAGE_TITLE = "Message";

        /// <summary>
        /// 获取日志输出信息
        /// </summary>
        public static string GetLogMessage(LogModel model)
        {
            string message = GetOutputString(MESSAGE_TITLE, model.Message);
            string reason = GetOutputString("Reason", model.Reason);
            string solution = GetOutputString("Solution", model.Solution);
            
            return message.InsertLast(reason).InsertLast(solution);
        }

        /// <summary>
        /// 获取单行输出日志
        /// </summary>
        public static string GetOutputString(string title, string msg)
        {
            if (!string.IsNullOrEmpty(msg))
            {
                return string.Format("{0}: {1}。\r\n", title, msg);
            }

            return msg;
        }
    }
}
